#include "MobileConfirmDlg.h"

#include <core/ImageMgr.h>
#include <core/StyleMgr.h>
#include <core/strings/md5.h>
#include <qbkernel/include/qb_base.h>
#include <qbtools/message/MessagePoster.h>
#include <uam/UserAccountManager.h>
#include <widgets/SCheckComboBox.h>
#include <widgets/SImageButton.h>
#include <widgets/SLineEdit.h>

#include <QHBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QPushButton>
#include <QSpacerItem>
#include <QStylePainter>
#include <QTimer>
#include <QTimerEvent>
#include <QVBoxLayout>
#include <QWidget>
#include <regex>

#include "../MessageProcess.h"
#include "MobileCfmUserInfoDlg.h"
SMobileVerifyLabel::SMobileVerifyLabel(const QString& t,
                                       QWidget* parent /*= nullptr*/)
    : QLabel(parent) {
  setText(t);
  setStyleSheet("text-decoration:underline;");
}

bool SMobileVerifyLabel::event(QEvent* e) {
  if (e->type() == QEvent::MouseButtonPress) {
    QMouseEvent* ev = static_cast<QMouseEvent*>(e);
    if (ev->button() == Qt::LeftButton) {
      emit clicked();
    }
  } else if (e->type() == QEvent::Enter) {
    setCursor(QCursor(Qt::PointingHandCursor));
  } else if (e->type() == QEvent::Leave) {
    setCursor(QCursor(Qt::ArrowCursor));
  }
  return QLabel::event(e);
}

MobileConfirmDlg::MobileConfirmDlg(QWidget* p /*= nullptr*/) : SPopupWindow(p) {
  setWindowFlag(Qt::FramelessWindowHint);
  setAttribute(Qt::WA_TranslucentBackground);

  setFixedSize(420, 600);
  SPopupWindow::setTitle(tr("手机验证"));
  getBtnClose()->hide();
  setStep(step_Start);

  loadRemainTimes();
  m_mainLayout = contentLayout();
  m_mainLayout->setSpacing(0);
  m_mainLayout->setContentsMargins(0, 0, 0, 0);

  m_fVItem = new QSpacerItem(0, 159);
  m_mainLayout->addSpacerItem(m_fVItem);

  // step_0: 立即验证界面
  m_mobileCfmDlg = new MobileCfmDlg(this);
  m_mainLayout->addWidget(m_mobileCfmDlg);

  m_sVItem = new QSpacerItem(0, 79);
  m_mainLayout->addSpacerItem(m_sVItem);
  m_remainMsg = getRemainTimeText();

  // 二维码以及label
  MobileCfmQrLabel* m_qrCodeAndLabel = new MobileCfmQrLabel(this);
  m_mainLayout->addWidget(m_qrCodeAndLabel);

  // step_Start
  connect(m_mobileCfmDlg->m_verify, &QPushButton::clicked, this,
          &MobileConfirmDlg::onQuickVerify);
  connect(m_mobileCfmDlg->m_nextTime, &SMobileVerifyLabel::clicked, this,
          &MobileConfirmDlg::onNextTime);
}

void MobileConfirmDlg::paintEvent(QPaintEvent* event) {
  SPopupWindow::paintEvent(event);
  QStylePainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing);
  // 绘制背景
  SImage* bgImg = ImgMgr::instance().image(
      "auth_mobile_verify_bg", WidgetStatus::kNormal, devicePixelRatioF());
  if (bgImg) {
    painter.drawPixmap(this->rect(), QPixmap::fromImage(*bgImg));
  }
  // 绘制title
  QRect titleR;
  QFontMetrics fm(font());
  int titleX = rect().x() + 6;
  int titleWidth = fm.horizontalAdvance(getTitle());
  painter.setPen(StyleMgr::instance().color("TextNormal"));
  titleR.setRect(titleX, rect().y() + 8, titleWidth, rect().height());
  painter.drawText(titleR, getTitle(), QTextOption(Qt::AlignLeft));
  if (m_step == step_Start) {
    if (!m_remainMsg.isEmpty()) {
      QRect remainMsgR;
      int remainMsgX = rect().x() + 184;
      int remainWidth = fm.horizontalAdvance(m_remainMsg);
      if (m_remainMsg == "(必须完成验证才能继续使用!)")
        remainMsgX = rect().x() + 128;
      painter.setPen(QColor(136, 140, 138));
      remainMsgR.setRect(remainMsgX, rect().y() + 390, remainWidth,
                         rect().height());
      painter.drawText(remainMsgR, m_remainMsg);
    }
  } else if (m_step == step_Verify_Mobile) {
    if (!m_mobileMsg.isEmpty()) {  // 绘制手机验证消息提示
      QRect mobileMsgR;
      int mobileMsgX = rect().x() + 178;
      int mobileWidth = fm.horizontalAdvance(m_mobileMsg);
      painter.setPen(QColor(254, 144, 13));
      mobileMsgR.setRect(mobileMsgX, rect().y() + 270, mobileWidth,
                         rect().height());
      painter.drawText(mobileMsgR, m_mobileMsg);
    }
  } else if (m_step == step_Verify_Info) {
    if (!m_userInfoMsg.isEmpty()) {  // 绘制个人信息提交失败消息提示
      QRect userInfoMsgR;
      int userInfoMsgX = rect().x() + 182;
      int userInfoWidth = fm.horizontalAdvance(m_userInfoMsg);
      painter.setPen(QColor(254, 144, 13));
      userInfoMsgR.setRect(userInfoMsgX, rect().y() + 402, userInfoWidth,
                           rect().height());
      painter.drawText(userInfoMsgR, m_userInfoMsg);
    }
  }
}

void MobileConfirmDlg::setStep(em_MobileCfmStep step) { m_step = step; }

void MobileConfirmDlg::hideMobileCfmWidget(em_MobileCfmStep step) {
  m_fVItem->changeSize(0, 0);
  m_sVItem->changeSize(0, 0);
  if (m_step == step_Start) {
    m_mobileCfmDlg->hide();
    setStep(step_Verify_Mobile);
  } else if (m_step == step_Verify_Mobile) {
    m_mobileVerify->hide();
    setStep(step_Verify_Info);
  } else if (m_step == step_Verify_Info) {
    m_mobileUserInfo->hide();
    setStep(step_Success);
  }
}

bool MobileConfirmDlg::verifyGetMessage(bool isQuickVerify) {
  if (m_step != step_Verify_Mobile) return false;
  if (m_mobileVerify->m_pwd->text().isEmpty()) {
    m_mobileMsg = tr("密码输入为空");
    return false;
  }
  if (m_mobileVerify->m_phoneNumber->text().isEmpty()) {
    m_mobileMsg = tr("手机号码输入为空");
    return false;
  }
  if (isQuickVerify && m_mobileVerify->m_codeVerify->text().isEmpty()) {
    m_mobileMsg = tr("验证码输入为空");
    return false;
  }
  if (!verifyPwd()) {
    m_mobileMsg = tr("密码错误");
    return false;
  }
  if (!verifyMobile()) {
    m_mobileMsg = tr("请输入正确手机号");
    return false;
  }
  return true;
}

bool MobileConfirmDlg::verifyPwd() const {
  std::string strEdit = m_mobileVerify->m_pwd->text().toStdString();

  const char* cMd5 = qb::MD5String(strEdit.c_str());
  QString qstrEdit = QString("%1").arg(cMd5);

  const CUserAccountInfo& usrInfo =
      SSUserAccountManager::instance().GetUserInfo();
  QString strPassWd = QString("%1").arg(usrInfo.m_Password);
  if (qstrEdit == strPassWd) return true;
  return false;
}

bool MobileConfirmDlg::verifyMobile() const {
  QString strEdit = m_mobileVerify->m_phoneNumber->text();
  std::regex pieces_regex("1[1-9]\\d{9}");
  std::smatch pieces_match;
  std::string phoneNum = strEdit.toStdString();
  bool bMatch = std::regex_match(phoneNum, pieces_match, pieces_regex);
  return bMatch;
}

bool MobileConfirmDlg::verifyUserInfo() {
  if (m_step != step_Verify_Info) return false;
  bool isFillInst = m_mobileUserInfo->m_institution->text().isEmpty();
  bool isFillDepart = m_mobileUserInfo->m_department->text().isEmpty();
  bool isFillPosition = m_mobileUserInfo->m_position->text().isEmpty();
  if (isFillInst || isFillDepart || isFillPosition) {
    m_userInfoMsg = tr("请填写您的机构/部门/职位哦~");
    return false;
  }
  return true;
}

void MobileConfirmDlg::verifyCodeMsg() {  // 验证手机验证码
  beginMobileVerifyTimer();
  requestMobileCodeMsg();
  connect(this, &MobileConfirmDlg::mobileVerifyCode, this,
          &MobileConfirmDlg::onRefreshUI);
}

void MobileConfirmDlg::beginMessageTimer() {
  m_nMessageTime = 60;  // 验证码计时默认为60秒
  if (m_timeCountdown == nullptr) {
    m_timeCountdown = new QTimer(this);
    m_timeCountdown->start(1000);
  } else {
    if (!m_timeCountdown->isActive()) m_timeCountdown->start(1000);
  }
  connect(m_timeCountdown, &QTimer::timeout, this,
          &MobileConfirmDlg::onCountDown);
}

void MobileConfirmDlg::beginMobileVerifyTimer() {
  enableButton(m_mobileVerify->m_quickVerify, true, tr("立即验证"));
  if (m_quickVerifyTimer == nullptr) {
    m_quickVerifyTimer = new QTimer(this);
    m_quickVerifyTimer->setInterval(30000);
    m_quickVerifyTimer->start();
  } else {
    if (!m_quickVerifyTimer->isActive()) {
      m_quickVerifyTimer->setInterval(30000);
      m_quickVerifyTimer->start();
    }
  }
  connect(m_quickVerifyTimer, &QTimer::timeout, this,
          &MobileConfirmDlg::onCountDown);
}

void MobileConfirmDlg::beginSubmitTimer() {
  enableButton(m_mobileUserInfo->m_submit, false, tr("提交"));
  if (m_submitTimer == nullptr) {
    m_submitTimer = new QTimer(this);
    m_submitTimer->setInterval(30000);
  } else {
    if (!m_submitTimer->isActive()) {
      m_submitTimer->start();
      m_submitTimer->setInterval(30000);
    }
  }
  connect(m_submitTimer, &QTimer::timeout, this,
          &MobileConfirmDlg::onCountDown);
}

void MobileConfirmDlg::reEnableTimerButton() {
  if (m_nMessageTime >= 1) {
    if (m_timeCountdown->isActive()) {
      m_quickVerifyTimer->stop();
      if (m_quickVerifyTimer->isActive()) m_timeCountdown->stop();
    }
    enableButton(m_mobileVerify->m_getCode, false, tr("重新获取"));
  }
}

void MobileConfirmDlg::enableButton(QPushButton* btn, bool enable,
                                    QString txt) {
  if (!txt.isEmpty()) btn->setText(txt);
  btn->setDisabled(enable);  // 按钮假死状态
}

void MobileConfirmDlg::requestMobileSendMsg() {
  qb::SSRequestMsg Req;
  Req.m_FuncID = E_FID_QB_MOBILE_SEND_MESSAGE;
  MessagePoster poster(&Req, [](qb::proto::Message& msg,
                                qb::SSRequestMsg* req) {
    qb::proto::VariantMap submsg;
    submsg.SetString("UserId",
                     SSUserAccountManager::instance().GetUserInfo().m_UserId);
    submsg.SetString(
        "mobile", SSUserAccountManager::instance().GetMobileConfirm().m_mobile);
    msg.SetMap("xQBMobileSendMessageReq", submsg);
  });
  poster.send(this);
}

void MobileConfirmDlg::requestMobileCodeMsg() {
  qb::SSRequestMsg Req;
  Req.m_FuncID = E_FID_QB_MOBILE_VERIFY_MESSAGE;
  MessagePoster poster(&Req, [this](qb::proto::Message& msg,
                                    qb::SSRequestMsg* req) {
    qb::proto::VariantMap submsg;
    submsg.SetString("UserId",
                     SSUserAccountManager::instance().GetUserInfo().m_UserId);
    submsg.SetString(
        "mobile", SSUserAccountManager::instance().GetMobileConfirm().m_mobile);
    submsg.SetString("vefifycationCode",
                     m_mobileVerify->m_codeVerify->text().toStdString());
    msg.SetMap("xQBMobileVerifyMessageReq", submsg);
  });
  poster.send(this);
}

void MobileConfirmDlg::requestNextTimeMsg() {
  qb::SSRequestMsg Req;
  Req.m_FuncID = E_FID_QB_MOBILE_VERIFY_NEST_TIMES;
  MessagePoster poster(
      &Req, [](qb::proto::Message& msg, qb::SSRequestMsg* req) {
        qb::proto::VariantMap submsg;
        submsg.SetString(
            "UserId", SSUserAccountManager::instance().GetUserInfo().m_UserId);
        msg.SetMap("xQBMobileVerifyNextTimesReq", submsg);
      });
  poster.send(this);
}

void MobileConfirmDlg::requestSubmitInfoMsg() {
  qb::SSRequestMsg Req;
  Req.m_FuncID = E_FID_QB_MOBILE_MODIFY_USEINFO;

  MessagePoster poster(&Req, [this](qb::proto::Message& msg,
                                    qb::SSRequestMsg* req) {
    qb::proto::VariantMap submsg;
    submsg.SetString("UserId",
                     SSUserAccountManager::instance().GetUserInfo().m_UserId);
    submsg.SetString(
        "companyName",
        m_mobileUserInfo->m_institution->text().toLocal8Bit().data());
    submsg.SetString(
        "dept", m_mobileUserInfo->m_department->text().toStdString().data());
    submsg.SetString("title",
                     m_mobileUserInfo->m_position->text().toStdString().data());
    submsg.SetString(
        "tel", m_mobileUserInfo->m_telephone->text().toStdString().data());
    submsg.SetString("qq", m_mobileUserInfo->m_qq->text().toStdString().data());
    std::set<int> selects;
    for (int i = 0; i <= 7; i++) {
      bool checked = m_mobileUserInfo->m_typeCheckBox->getCheck(i);
      if (checked) selects.insert(i);
    }
    QString szSelect = "";
    for (auto it : selects) {
      QString szData = m_mobileUserInfo->m_typeCheckBox->getDataText(it);
      if (szData.length() <= 0) continue;
      if (szSelect.length() > 0) szSelect += "|";
      szSelect += szData;
    }
    submsg.SetString("businessType", szSelect.toStdString());
    msg.SetMap("xQBMobileModifyUserInfoReq", submsg);
  });
  poster.send(this);
}

void MobileConfirmDlg::loadRemainTimes() {
  const CUserMobileConfirmInfo& info =
      SSUserAccountManager::instance().GetMobileConfirm();
  m_nRemainTimes = info.m_restTimes;
  if (info.m_verifyMobile) m_nRemainTimes = 1;
}

QString MobileConfirmDlg::getRemainTimeText() {
  if (m_nRemainTimes > 5) {
    log_info("mobile confirm step have a error Remaintimes :%d",
             m_nRemainTimes);
    m_nRemainTimes = 5;
  }
  if (m_nRemainTimes > 1) {
    QString strTemp = QString("(剩余%d次)").arg(m_nRemainTimes);
    return strTemp;
  } else {
    {
      const CUserMobileConfirmInfo& info =
          SSUserAccountManager::instance().GetMobileConfirm();
      if (info.m_verifyMobile) return "";
    }
    return "(必须完成验证才能继续使用!)";
  }
}

void MobileConfirmDlg::onRefreshUI(bool isPassVerify) {
  if (isPassVerify) {
    if (m_quickVerifyTimer->isActive()) m_quickVerifyTimer->stop();
    hideMobileCfmWidget(m_step);
    m_fVItem->changeSize(0, 45);
    if (m_mobileUserInfo == nullptr) {
      m_mobileUserInfo = new MobileCfmUserInfoDlg(this);
      m_mobileUserInfo->setFixedSize(358, 375);  // step_Verify_Info
    }
    m_mainLayout->insertWidget(1, m_mobileUserInfo);
    m_sVItem->changeSize(0, 25);
    connect(m_mobileUserInfo->m_submit, &QPushButton::clicked, this,
            &MobileConfirmDlg::onSumbit);
  } else {
    m_mobileMsg = tr("请输入正确验证码");
    if (m_quickVerifyTimer->isActive()) {
      reEnableTimerButton();
    }
    enableButton(m_mobileVerify->m_quickVerify, false, tr("立即验证"));
    update();
  }
}

void MobileConfirmDlg::onSuccessSubmit() {
  if (m_step != step_Verify_Info) return;
  m_submitTimer->stop();
  hideMobileCfmWidget(step_Verify_Info);
  QVBoxLayout* v = new QVBoxLayout;
  v->setContentsMargins(176, 208, 0, 0);
  QLabel* iconDoneLabel = new QLabel(this);
  SImage* iconDoneImg = ImgMgr::instance().image(
      "auth_icon_check_done", WidgetStatus::kNormal, devicePixelRatioF());
  if (iconDoneImg) iconDoneLabel->setPixmap(QPixmap::fromImage(*iconDoneImg));
  v->addWidget(iconDoneLabel);
  m_mainLayout->insertLayout(1, v);
  QVBoxLayout* vl = new QVBoxLayout;
  vl->setContentsMargins(123, 10, 0, 0);
  QLabel* text = new QLabel(tr("感谢您的耐心配合,验证已完毕"), this);
  vl->addWidget(text);
  m_mainLayout->insertLayout(2, vl);
  m_sVItem->changeSize(0, 163);
  m_dlgCloseTimer = new QTimer(this);
  m_dlgCloseTimer->setInterval(3000);
  m_dlgCloseTimer->start();
  connect(m_dlgCloseTimer, &QTimer::timeout, this,
          &MobileConfirmDlg::onCountDown);
}

void MobileConfirmDlg::onDataArrived(const qb::SSAckMsg& msg) {
  if (!msg.m_pRet) return;
  int funcId = msg.m_FuncID;
  if (E_FID_QB_MOBILE_SEND_MESSAGE == funcId)  // 发送验证码
  {
    xQBMobileSendMessageAck_c* pData = (xQBMobileSendMessageAck_c*)msg.m_pRet;
    if (!pData) return;
    emit mobileSendCodeData(pData->m_data);
  } else if (E_FID_QB_MOBILE_VERIFY_MESSAGE == funcId)  // 验证手机验证码
  {
    xQBMobileVerifyMessageAck_c* pData =
        (xQBMobileVerifyMessageAck_c*)msg.m_pRet;
    if (!pData) return;
    emit mobileVerifyCode(pData->m_data);
  } else if (E_FID_QB_MOBILE_VERIFY_NEST_TIMES == funcId)  // 下次再说
  {
    xQBMobileVerifyNextTimesAck_c* pData =
        (xQBMobileVerifyNextTimesAck_c*)msg.m_pRet;
    if (!pData) return;
  } else if (E_FID_QB_MOBILE_MODIFY_USEINFO == funcId)  // 修改手机验证用户信息
  {
    xQBMobileModifyUserInfoAck_c* pData =
        (xQBMobileModifyUserInfoAck_c*)msg.m_pRet;
    if (!pData) return;
    emit mobileModifyUserInfo();
  }
}

void MobileConfirmDlg::onGetCode() {
  m_mobileMsg.clear();
  if (verifyGetMessage()) {
    beginMessageTimer();
    requestMobileSendMsg();
    connect(this, &MobileConfirmDlg::mobileSendCodeData, this,
            &MobileConfirmDlg::onDealCodeData);
  }
  update();
}

void MobileConfirmDlg::onQuickVerify() {
  if (m_step == step_Start) {
    hideMobileCfmWidget(step_Start);
    m_fVItem->changeSize(0, 99);
    if (m_mobileVerify == nullptr) {
      m_mobileVerify = new MobileCfmVerifyDlg(this);
      m_mobileVerify->setFixedSize(335, 310);  // step_Verify_Mobile
    }
    m_mainLayout->insertWidget(1, m_mobileVerify);
    m_sVItem->changeSize(0, 29);

    connect(m_mobileVerify->m_getCode, &QPushButton::clicked, this,
            &MobileConfirmDlg::onGetCode);
    connect(m_mobileVerify->m_quickVerify, &QPushButton::clicked, this,
            &MobileConfirmDlg::onQuickVerify);
    connect(m_mobileVerify->m_nextTime, &SMobileVerifyLabel::clicked, this,
            &MobileConfirmDlg::onNextTime);
  } else if (m_step == step_Verify_Mobile) {
    if (!verifyGetMessage(true)) {
      update();
      return;
    }
    verifyCodeMsg();  // 验证手机验证码
  }
}

void MobileConfirmDlg::onNextTime() {
  CUserMobileConfirmInfo& info =
      SSUserAccountManager::instance().GetMobileConfirm();
  if (info.IsInitial() && info.m_verifyMobile) {
    close();
  } else if (info.IsInitial() &&
             SSUserAccountManager::instance().GetMobileConfirm().m_restTimes <=
                 1) {
    close();
  } else {
    requestNextTimeMsg();
    close();
  }
}

void MobileConfirmDlg::onCountDown() {
  QTimer* timer = qobject_cast<QTimer*>(QObject::sender());
  if (timer == m_timeCountdown && m_step == step_Verify_Mobile) {
    if (m_nMessageTime <= 1) {
      m_timeCountdown->stop();
      reEnableTimerButton();
    } else {
      m_nMessageTime--;
      QString txt =
          QString(tr("重新获取(%1s)")).arg(QString::number(m_nMessageTime));
      enableButton(m_mobileVerify->m_getCode, true, txt);
    }
  } else if (timer == m_quickVerifyTimer && m_step == step_Verify_Mobile) {
    m_quickVerifyTimer->stop();  // 超过30秒自动停止
    enableButton(m_mobileVerify->m_quickVerify, false, tr("立即验证"));
    QMessageBox::information(this, "提示", tr("验证超时，请重试"));
  } else if (timer == m_submitTimer && m_step == step_Verify_Info) {
    m_submitTimer->stop();
    enableButton(m_mobileUserInfo->m_submit, false, tr("提交"));
    QMessageBox::information(this, "提示", "提交消息超时，请重新提交");
  } else if (timer == m_dlgCloseTimer && m_step == step_Success) {
    m_dlgCloseTimer->stop();
    close();
  }
}

void MobileConfirmDlg::onSumbit() {
  if (verifyUserInfo()) {
    beginSubmitTimer();
    requestSubmitInfoMsg();
    connect(this, &MobileConfirmDlg::mobileModifyUserInfo, this,
            &MobileConfirmDlg::onSuccessSubmit);
  } else
    update();
}

void MobileConfirmDlg::onDealCodeData(int data) {
  if (data == 1)
    m_mobileMsg = "该手机号已被验证，如有疑问请联系客服";
  else if (data == 2)
    m_mobileMsg = "手机验证码发送失败!";
  else if (data == 3)
    m_mobileMsg = "该用户已经认证手机!";

  if (!m_mobileMsg.isEmpty()) {
    m_timeCountdown->stop();
    reEnableTimerButton();
    update();
  }
}

MobileCfmDlg::MobileCfmDlg(QWidget* p /*= nullptr*/) : QWidget(p) {
  QVBoxLayout* vLayout = new QVBoxLayout(this);
  vLayout->setContentsMargins(55, 0, 90, 0);
  QString str =
      tr("您好,为了帮助您更方便快捷地使用qeubee,我们\n推出了新功能,"
         "只要现在进行手机验证,以后就可以");
  QLabel* fLabel = new QLabel(str, this);
  vLayout->addWidget(fLabel);
  vLayout->setSpacing(0);

  QHBoxLayout* hLayout = new QHBoxLayout;
  hLayout->setContentsMargins(0, 0, 0, 0);
  vLayout->addLayout(hLayout);

  str = tr("使用手机号作为登录名");
  QLabel* sLabel = new QLabel(str, this);
  sLabel->setStyleSheet("QLabel{color:rgb(254, 144, 13);}");
  hLayout->addWidget(sLabel);
  hLayout->addSpacing(0);

  str = tr("进行登录，原有的邮箱也");
  QLabel* tLabel = new QLabel(str, this);
  tLabel->setStyleSheet(
      (QString("color:#%1")
           .arg(StyleMgr::instance().color("TextNormal").rgb(), 0, 16)));
  hLayout->addWidget(tLabel);

  str = tr("可以继续使用。");
  QLabel* forthLabel = new QLabel(str, this);
  vLayout->addWidget(forthLabel);

  QSpacerItem* vItem = new QSpacerItem(0, 68);
  vLayout->addSpacerItem(vItem);

  QHBoxLayout* h = new QHBoxLayout;
  h->setContentsMargins(30, 0, 0, 0);
  m_verify = new QPushButton(tr("立即验证"), this);
  m_verify->setFixedSize(100, 30);

  QString style =
      QString(
          "QPushButton{background:#%1; "
          "border-radius:0px;color:#FFE5C7}\nQPushButton:hover{background:#%2}")
          .arg(StyleMgr::instance().color("ButtonNormal").rgb(), 0, 16)
          .arg(StyleMgr::instance().color("Hover").rgb(), 0, 16);
  m_verify->setStyleSheet(style);

  h->addStretch();
  h->addWidget(m_verify);
  h->addStretch();
  vLayout->addLayout(h);

  vLayout->addSpacing(17);

  QHBoxLayout* hBoxLayout = new QHBoxLayout;
  hBoxLayout->setContentsMargins(30, 0, 0, 0);
  m_nextTime = new SMobileVerifyLabel(tr("下次再说"), this);
  hBoxLayout->addStretch();
  hBoxLayout->addWidget(m_nextTime);
  hBoxLayout->addStretch();
  vLayout->addLayout(hBoxLayout);
}

MobileCfmQrLabel::MobileCfmQrLabel(QWidget* p /*= nullptr*/) : QWidget(p) {
  QHBoxLayout* hL = new QHBoxLayout(this);
  hL->setContentsMargins(48, 0, 0, 0);
  // 垂直布局1
  QVBoxLayout* vTextLayout = new QVBoxLayout;
  vTextLayout->setContentsMargins(0, 0, 0, 0);
  QLabel* text = new QLabel(
      tr("客服热线:400-119-9898\n关注森浦公众号, 联系在线客服"), this);
  vTextLayout->addWidget(text);

  QSpacerItem* vItem = new QSpacerItem(0, 60);
  vTextLayout->addSpacerItem(vItem);

  hL->addLayout(vTextLayout);
  hL->addSpacing(56);
  // 垂直布局2
  QVBoxLayout* vImageLayout = new QVBoxLayout;
  vImageLayout->setContentsMargins(0, 0, 0, 0);
  QSpacerItem* vItemSpace = new QSpacerItem(0, 26);
  vImageLayout->addSpacerItem(vItemSpace);

  QLabel* wechatQrcodeLabel = new QLabel(this);
  SImage* qrCodeImg = ImgMgr::instance().image(
      "auth_wechat_offical_qrcode", WidgetStatus::kNormal, devicePixelRatioF());
  if (qrCodeImg) wechatQrcodeLabel->setPixmap(QPixmap::fromImage(*qrCodeImg));
  vImageLayout->addWidget(wechatQrcodeLabel, Qt::AlignRight | Qt::AlignBottom);
  hL->addLayout(vImageLayout);
}